cmake_minimum_required(VERSION 3.22.1)

SET(lib_name ffpmeg60)

include_directories(include)

message("CMAKE_SOURCE_DIR:" ${CMAKE_SOURCE_DIR})

set(ffmpegLibsDir ${CMAKE_SOURCE_DIR}/ffmpeg/jniLibs/${ANDROID_ABI})
message("ffmpegLibsDir:" ${ffmpegLibsDir})
file(GLOB cppFfmpegSrc ${CMAKE_SOURCE_DIR}/ffmpeg/cppSrc/*.cpp ${CMAKE_SOURCE_DIR}/ffmpeg/cppSrc/*.c)
message("cppFfmpegSrc:" ${cppFfmpegSrc})

add_library(
        avcodec
        SHARED
        IMPORTED)
set_target_properties(
        avcodec
        PROPERTIES
        IMPORTED_LOCATION
        ${ffmpegLibsDir}/libavcodec.so)
add_library(
        avformat
        SHARED
        IMPORTED)
set_target_properties(
        avformat
        PROPERTIES
        IMPORTED_LOCATION
        ${ffmpegLibsDir}/libavformat.so)

add_library(
        avfilter
        SHARED
        IMPORTED)
set_target_properties(
        avfilter
        PROPERTIES
        IMPORTED_LOCATION
        ${ffmpegLibsDir}/libavfilter.so)

add_library(
        avutil
        SHARED
        IMPORTED)
set_target_properties(
        avutil
        PROPERTIES
        IMPORTED_LOCATION
        ${ffmpegLibsDir}/libavutil.so)

add_library(
        swresample
        SHARED
        IMPORTED)
set_target_properties(
        swresample
        PROPERTIES
        IMPORTED_LOCATION
        ${ffmpegLibsDir}/libswresample.so)

add_library(
        swscale
        SHARED
        IMPORTED)
set_target_properties(
        swscale
        PROPERTIES
        IMPORTED_LOCATION
        ${ffmpegLibsDir}/libswscale.so)

find_library( # Sets the name of the path variable.
        log-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        log)
find_library( # Sets the name of the path variable.
        Z-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        Z)
find_library( # Sets the name of the path variable.
        android-lib

        # Specifies the name of the NDK library that
        # you want CMake to locate.
        android)

add_library( # Sets the name of the library.
        ${lib_name}
        # Sets the library as a shared library.
        SHARED
        # Provides a relative path to your source file(s).
        ${cppFfmpegSrc})
#target_link_libraries(${lib_name} PRIVATE libyuv)
target_link_libraries( # Specifies the target library.
        ${lib_name}
        ${log-lib}
        ${android-lib}
        yuv
        avformat
        avcodec
        avutil
        swscale
        swresample
        avfilter
        # Links the target library to the log library
        # included in the NDK.

        ${Z-lib})
